package com.example.controller;

import com.example.mapper.DrugAdminMapper;
import com.example.pojo.dto.DrugAdminRegDTO;
import com.example.pojo.dto.DrugDTO;
import com.example.pojo.vo.DrugAdminVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DrugAdminController {
    @Autowired(required = false)
    DrugAdminMapper mapper;
    @RequestMapping("/admin/login")
    public int login(@RequestBody DrugDTO drugUser){
        DrugAdminVO u = mapper.selectByUsername(drugUser.getUsername());
        if (u!=null){
            if (u.getPassword().equals(drugUser.getPassword())){
                return 1;
            }
            return 3;
        }
        return 2;
    }

    @RequestMapping("/admin/reg")
    public int reg(@RequestBody DrugAdminRegDTO drugAdmin){
        DrugAdminVO u = mapper.selectByUsername(drugAdmin.getUsername());
            if (u!=null){
                return 2;
            }else {
                mapper.insertDrugAdmin(drugAdmin);
                return 1;
            }
    }
}
